package com.tfy.liquor.bean;

import com.tfy.liquor.set.CodeSet;
import lombok.Data;

/**
 *接口返回类，所有接口的返回数据都通过这个类进行封装返回到前端
 */
@Data
public class Result {
    private Integer code;   // 返回代码
    private String msg; // 消息
    private String key; // 秘钥
    private Object data;    //数据

    public Result() {
    }

    public Result(Object data) {
        this.data = data;
    }

    public Result(String key) {
        this.key = key;
    }

    public Result(Object data, String key) {
        this.data = data;
        this.key = key;
    }

    public Result(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Result(int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    /**
     * 返回成功
     *
     * @return
     */
    public Result ok() {
        this.code = CodeSet.Ok.getCode();
        this.msg = CodeSet.Ok.getMsg();
        return this;
    }

    /**
     * 返回成功
     *
     * @param msg
     * @return
     */
    public Result ok(String msg) {
        this.code = CodeSet.Ok.getCode();
        this.msg = msg;
        return this;
    }

    /**
     * 返回成功,并返回数据
     *
     * @param data
     * @return
     */
    public Result ok(Object data) {
        this.code = CodeSet.Ok.getCode();
        this.msg = "成功";
        this.data = data;
        return this;
    }

    /**
     * 返回失败
     *
     * @return
     */
    public Result error() {
        this.code = CodeSet.Error.getCode();
        this.msg = CodeSet.Error.getMsg();
        return this;
    }

    /**
     * 返回失败
     *
     * @param msg
     * @return
     */
    public Result error(String msg) {
        this.code = CodeSet.Error.getCode();
        this.msg = msg;
        return this;
    }

    /**
     * 验证码错误或为空，不添加数据
     *
     * @return
     */
    public Result errorCode() {
        this.code = CodeSet.Bad_Code.getCode();
        this.msg = CodeSet.Bad_Code.getMsg();
        return this;
    }

    /**
     * 返回参数错误
     */
    public Result bad_CodeIsNull() {
        this.code = CodeSet.Bad_CodeIsNull.getCode();
        this.msg = CodeSet.Bad_CodeIsNull.getMsg();
        return this;
    }

    /**
     * 返回未登录
     *
     * @return
     */
    public Result no_Login() {
        this.code = CodeSet.No_Login.getCode();
        this.msg = CodeSet.No_Login.getMsg();
        return this;
    }

}
